import Taro from '@tarojs/taro';
import u from 'updeep'
import request from '../util/request'
const INITDATA = {
  listData: {}, // 列表数据
  id: '',
  ygfcVisible: false, // 是否展示更多
  jycpVisible: false, // 是否展示更多
  qyxxVisible: false, // 是否展示更多
  hzkhVisible: false, // 是否展示更多
  zzzsVisible: false, // 是否展示更多
  descVisible: false, // 是否展示更多
}
export default {
  namespace: 'companyDetail',
  state: {...INITDATA},
  reducers: {
    updateState(state, {payload}) {
      return u({
        ...payload
      }, state)
    },
    initData(state, action) {
      return {
        ...state,
        ...action.payload,
        ...INITDATA
      }
    }
  },
  effects: {
    // 获取列表数据
    * loadData({payload = {}}, {select, put, call}) {
      const { id } = yield select(({companyDetail}) => companyDetail)
      const {data} = yield call(request, {
        url: SERVERURL + '/service/business/' + id,
        data: {},
        method: 'GET',
      })

      if (data && data.data) {
        const d = data.data || {};
        yield put({
          type: 'updateState',
          payload: {
            listData: d,
          }
        })
      } else {
        Taro.showToast({
          title: (data || {}).msg || '获取列表数据失败',
          icon: 'none'
        })
      }
    },
  }
};
